package com.itrip.biz.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itrip.beans.domain.ItripLabelDic;
import com.itrip.beans.vo.AreaDicVo;
import com.itrip.beans.vo.HotCityVo;
import com.itrip.dao.ItripAreaDicMapper;
import com.itrip.dao.ItripLabelDicMapper;
import com.itrip.utils.RedisAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HotelService {

    private final static String BIZ_HOTEL_SERVICE = "BIZ:HOTEL";
    @Autowired
    private ItripAreaDicMapper itripAreaDicMapper;
    @Autowired
    private ItripLabelDicMapper itripLabelDicMapper;
    @Autowired
    private RedisAPI redisAPI;

    public synchronized List<HotCityVo> queryhotcity(Integer isChina) {
        /*List<HotCityVo> list = itripAreaDicMapper.selectHotCity(isChina);*/
        String HotCity = redisAPI.get(BIZ_HOTEL_SERVICE+isChina);
        if(HotCity == null){
            List<HotCityVo> list = itripAreaDicMapper.selectHotCity(isChina);
            redisAPI.set(BIZ_HOTEL_SERVICE+isChina, JSONObject.toJSONString(list));
            return list;
        }else{
            return JSONArray.parseArray(HotCity,HotCityVo.class);
        }
    }

    public List<ItripLabelDic> queryhotelfeature() {
        return itripLabelDicMapper.queryhotelfeature();
    }

    public List<AreaDicVo> querytradearea(Integer id) {
        return itripAreaDicMapper.querytradearea(id);
    }
}
